# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=xapian-bindings
pkgver=1.4.26
pkgrel=0
pkgdesc="Binding libraries for xapian"
url="http://www.xapian.org"
arch="all"
license="GPL-2.0-or-later"
# Disabled check for now since ruby smoketest fails
options="!check"

_lua_ver=5.3
_php_ver=8.2
_py_ver=3
_tcl_ver=8.6
_perl_ver=5

_py_makedepends="
	py$_py_ver-sphinx-autobuild py$_py_ver-sphinx
	py$_py_ver-requests py$_py_ver-setuptools
	py$_py_ver-urllib3 py$_py_ver-chardet py$_py_ver-idna
	python$_py_ver-dev py$_py_ver-certifi"
_perl_makedepends="perl-dev"
_lua_makedepends="lua$_lua_ver-dev lua$_lua_ver-libs lua5.1-dev"
_ruby_makedepends="ruby-dev ruby ruby-rdoc"
_tcl_makedepends="tcl-dev"
_php_makedepends="php${_php_ver/./}-dev"

makedepends="automake autoconf libtool bash xapian-core-dev sphinx
	$_py_makedepends
	$_perl_makedepends
	$_lua_makedepends
	$_ruby_makedepends
	$_tcl_makedepends
	$_php_makedepends"
subpackages="$pkgname-perl $pkgname-lua $pkgname-doc
	$pkgname-python$_py_ver $pkgname-ruby $pkgname-tcl $pkgname-php${_php_ver/./}"
source="http://www.oligarchy.co.uk/xapian/$pkgver/xapian-bindings-$pkgver.tar.xz"

prepare() {
	default_prepare
	aclocal && autoconf
	libtoolize
	autoreconf -fvi
	# workaround for non-existing-dir while build docs for python
	mkdir -p python3/docs/_static
}

build() {
	export LUA=/usr/bin/lua$_lua_ver
	export LUA_INC=/usr/include/lua$_lua_ver
	export LUA_LIB=/usr/lib/lua/$_lua_ver
	export LUA_SO=.so
	export PERL=/usr/bin/perl
	export PERL_LIB=/usr/share/perl$_perl_ver/vendor_perl
	export PERL_ARCH=/usr/share/perl$_perl_ver/vendor_perl
	export PHP=/usr/bin/php${_php_ver/./}
	export PHP_CONFIG=/usr/bin/php-config${_php_ver/./}
	export PYTHON3=/usr/bin/python$_py_ver
	export RUBY=/usr/bin/ruby
	export RUBY_LIB=/usr/lib/ruby
	export RUBY_LIB_ARCH=/usr/lib/ruby
	export TCLSH=/usr/bin/tclsh$_tcl_ver
	export TCL_LIB=/usr/lib/tcl$_tcl_ver/$pkgname-$pkgver
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-perl \
		--with-lua \
		--with-php \
		--without-php7 \
		--with-python$_py_ver \
		--with-ruby \
		--with-tcl \
		XAPIAN_CONFIG=/usr/bin/xapian-config
	make
}

package() {
	make DESTDIR=$pkgdir install
}

perl() {
	pkgdesc="Perl bindings for the Xapian search engine library"

	install -d "$subpkgdir"/usr/share/perl$_perl_ver
	mv "$pkgdir"/usr/share/perl$_perl_ver "$subpkgdir"/usr/share/
}

lua() {
	pkgdesc="Lua $_lua_ver bindings for the Xapian search engine library"

	install -d "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/lua "$subpkgdir"/usr/lib
}

python3() {
	pkgdesc="Python$_py_ver bindings for the Xapian search engine library"

	install -d "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python$_py_ver* "$subpkgdir"/usr/lib
}

ruby() {
	pkgdesc="Ruby bindings for the Xapian search engine library"

	install -d "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/ruby "$subpkgdir"/usr/lib
}

tcl() {
	pkgdesc="Tcl bindings for the Xapian search engine library"

	install -d "$subpkgdir"/usr/lib/tcl$_tcl_ver
	mv "$pkgdir"/usr/lib/tcl$_tcl_ver/$pkgname-$pkgver "$subpkgdir"/usr/lib/tcl$_tcl_ver
}

php82() {
	pkgdesc="PHP8 bindings for the Xapian search engine library"
	mkdir -p "$subpkgdir"/etc/php${_php_ver/./}/conf.d
	echo ';extension=xapian.so' > "$subpkgdir/etc/php${_php_ver/./}/conf.d/xapian.ini"

	amove usr/lib/php${_php_ver/./}
}


sha512sums="
9ab6c8f7092c6d353341a2de565501ba4eadd47c78a472c54c9f41de08ac5b42382236a4b66f03257cd505464e1b6e9eaf2ab05c1d6e984cc641738dd43b3314  xapian-bindings-1.4.26.tar.xz
"
